/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.ac.c0910g.assignment.DAO;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import vn.ac.c0910g.assignment.Entity.Orders;
import vn.ac.c0910g.assignment.Entity.OrdersFacade;

/**
 *
 * @author BachLe
 */
public class OrdersDAO {
    OrdersFacade ordersFacade = lookupOrdersFacadeBean();

    public OrdersDAO(){

    }
    private OrdersFacade lookupOrdersFacadeBean() {
        try {
            Context c = new InitialContext();
            return (OrdersFacade) c.lookup("java:global/Alluring_Decors/Alluring_Decors-ejb/OrdersFacade!vn.ac.c0910g.assignment.Entity.OrdersFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<Orders> getAllOrders(){
        return this.ordersFacade.findAll();
    }

    public void addOrder(Orders or){
        ordersFacade.create(or);
    }

    public void updateOrder(Orders or){
        ordersFacade.edit(or);
    }

    public void deleteOrder(Orders or){
        ordersFacade.remove(or);
    }

    public Orders findOrdersById(String Id){
        return ordersFacade.find(Id);
    }
}
